import {useEffect} from'react'
import {useLocation,useNavigate} from 'react-router-dom'
import useGetUserInfo from './useGetUserInfo'
import { isLoginOrRegister,MANAGE_INDEX_PATHNAME,isNoNeedUserInfo ,LOGIN_PATHNAME} from "../router/index";
function useNavPage(waitingUserData:boolean){
  const {username}=useGetUserInfo()
  const {pathname}=useLocation()
  const nav=useNavigate()
  useEffect(()=>{
    if(waitingUserData) return
    console.log(pathname,'pathnamepathname',waitingUserData,username);
    
    if(username){
      if(isLoginOrRegister(pathname)){
        // nav(MANAGE_INDEX_PATHNAME)
        nav(-1)   
      }
      return
    }
    if(isNoNeedUserInfo(pathname)){
      return
    }else{
      nav(LOGIN_PATHNAME)
    }
  },[waitingUserData,username,pathname])
}
export default useNavPage